package thread.wang_bao_ling.c26;

import util.RandomArr;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;

/**
 * @Auther: luobiao
 * @Date: 2020/7/20 07:14
 * @Description:
 */
public class TestForkJoin {
    public static void main(String[] args) throws Exception {
        // 创建随机数组成的数组:
        int[] array = RandomArr.getArr(400);
        // fork/join task:
        ForkJoinPool fjp = new ForkJoinPool(4); // 最大并发数4
        ForkJoinTask<Integer> task = new SumTask(array, 0, array.length);
        long startTime = System.currentTimeMillis();
        Integer result = fjp.invoke(task);
        long endTime = System.currentTimeMillis();
        System.out.println("Fork/join sum: " + result + " in " + (endTime - startTime) + " ms.");
    }

}
